import { Middleware } from "nb2";
import { getToken } from "./utils.js";
import { ResBody } from "./model.js";

export const handleAuth: Middleware = async (ctx, next) => {
  const token = await getToken(ctx);
  //传递token
  ctx.custom.token = token;
  if (!token) {
    return ctx.json<ResBody>({ code: 401, msg: "请重新登录" });
  }
  next();
};
